<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #673ab7;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 300px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 300px;
    height: 178px;
    display: block;
  }
</style>

<template>
  <div class="app-container">


    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-date-picker
        v-model="value2"
        type="daterange"
        value-format="yyyy-MM-dd"
        align="right"
        unlink-panels
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        :picker-options="pickerOptions">
      </el-date-picker> &nbsp;
      <el-form-item prop="all">
        <el-input
          v-model="queryParams.all"
          placeholder="支持姓名/工号查询"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 办理转正 -->
    <el-dialog :title="title" :visible.sync="dialogVisible" width="70%" append-to-body>
      <center>
        <h1>办理转正</h1>
      </center>
      <el-divider></el-divider>
      <el-form ref="form" :model="zzform" :rules="rules" label-width="100px">
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="归属部门" prop="deptName">
              <treeselect   @input="parentIdChange" v-model="zzform.deptName"   :options="deptOptions" :show-count="true" placeholder="请选择归属部门"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="岗位" prop="sySalary">
              <el-input v-model="zzform.positionApplied" placeholder="请输入"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="职称" prop="post">
              <el-input v-model="zzform.post" placeholder="请输入"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工作性质" prop="workNature">
              <el-input v-model="zzform.workNature" placeholder="请输入"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="转正日期" prop="zzTime">

              <el-date-picker
                v-model="zzform.zzTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="转正日期">
              </el-date-picker>

            </el-form-item>
          </el-col>
        </el-row>


      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-on='{click:zzSubmit}'>确定</el-button>
        <el-button @click="dialogVisible =false">取 消</el-button>
      </div>
    </el-dialog>
    <!--    @selection-change="handleSelectionChange"-->
    <el-table v-loading="loading" :data="employeefilesList">
      <el-table-column label="姓名" align="center" prop="name"/>
      <el-table-column label="工号" align="center" prop="jobNo"/>
      <el-table-column label="部门" align="center" prop="dname"/>
      <el-table-column label="岗位" align="center" prop="positionApplied"/>
      <el-table-column label="职称" align="center" prop="post"/>
      <!--<el-table-column label="企业" align="center" prop="enterprise"/>-->
<!--
      <el-table-column label="项目组" :show-overflow-tooltip="true" align="center" prop="proName" width="100"/>
-->
      <el-table-column label="工作性质" align="center" prop="workNature"/>
      <el-table-column label="到岗日期" align="center" prop="employmentDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.employmentDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="试用期" align="center" prop="probationPeriod"/>
      <el-table-column label="转正日期" align="center" prop="employmentDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.zzTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="转正状态" align="center" prop="zzStatus" width="180">
        <template slot-scope="scope">
          <span>未办理</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" width="160" align="center" class-name="small-padding fixed-width" fixed="right">

        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-share"
            @click="dialog(scope.row.id)"

          >办理转正
          </el-button>


        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


  </div>
</template>

<script>
  import {
    getEmployeefiles,
    listRoster, updateEmployeefiles,
  } from "@/api/system/employeefiles";

  import Treeselect from '@riophae/vue-treeselect'
  import "@riophae/vue-treeselect/dist/vue-treeselect.css"
  import "@riophae/vue-treeselect/dist/vue-treeselect.css"
  import {addStation, updateStation} from '@/api/system/station'
  import {deptTreeSelect } from "@/api/system/user"

  export default {
    components: {Treeselect},
    name: "Employeefiles",
    data() {
      return {
        deptOptions: undefined,
        // 显示搜索条件
        showSearch: true,
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        value2: "",
        zzform: {
          id: null,
          dname: null,
          positionApplied: null,
          post: null,
          workNature: null,
          zzTime: null,
          status: null
        },
        zzTime: null,
        enclosure: {
          certificateFront: '',
          certificateBack: '',
          diploma: '',
          degreesDiploma: '',
          leavingCertificate: '',
          examinationReport: '',
          empId: null
        },

        // 遮罩层
        loading: true,


        // 总条数
        total: 0,
        statisticsNum: {
          count0: null,
          count1: null,
          count2: null,
          count3: null
        },


        // 员工档案表格数据
        employeefilesList: [],
        employeefiles: {
          id: null,
          name: null,
          gender: null,
          age: null,
          dateOfBirth: null,
          isMarriage: null,
          isBirth: null,
          ethnicGroup: null,
          politicalOutlook: null,
          documentType: null,
          identificationNumber: null,
          registeredResidence: null,
          phone: null,
          mailbox: null,
          currentAddress: null,
          emergencyContact: null,
          emergencyContactNumber: null,
          schoolName: null,
          education: null,
          major: null,
          bankCardNo: null,
          bankAddress: null,
          bankName: null,
          jobNo: null,
          deptName: null,
          title: null,
          workNature: null,
          employmentDate: null,
          probationPeriod: null,
          positionApplied: null,
          positionType: null,
          enterprise: null,
          status: null,
          enrollmentRegistration: null,
          contractSigning: null,
          socialSecuritySalary: null,
          isDelete: null,
        },

        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,

        dialogVisible: false,


        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: null,
          gender: null,
          age: null,
          dateOfBirth: null,
          isMarriage: null,
          isBirth: null,
          ethnicGroup: null,
          politicalOutlook: null,
          documentType: null,
          identificationNumber: null,
          registeredResidence: null,
          phone: null,
          mailbox: null,
          currentAddress: null,
          emergencyContact: null,
          emergencyContactNumber: null,
          schoolName: null,
          education: null,
          major: null,
          bankCardNo: null,
          bankAddress: null,
          bankName: null,
          jobNo: null,
          deptName: null,
          title: null,
          workNature: null,
          employmentDate: null,
          probationPeriod: null,
          positionApplied: null,
          positionType: null,
          enterprise: null,
          status: null,
          enrollmentRegistration: null,
          contractSigning: null,
          socialSecuritySalary: null,
          isDelete: null,
          all: null,
        },

        // 表单参数
        form: {},
        // 表单校验
        rules: {
          zzTime: [
            {required: true, message: '转正日期不能为空', trigger: 'blur'}
          ],
        }
      };
    },
    created() {

      this.getList();
      this.getDeptTree()
    },
    methods: {
      download(conId) {
        this.$download.hetzip(conId)
      },
      /** 查询员工档案列表 */
      getList() {
        this.loading = true;
        listRoster(this.queryParams).then(response => {
          this.employeefilesList = response.rows;
          /*employmentDate probationPeriod*/
          this.total = response.total;
        });
        this.loading = false;
      },


      /**办理离职按钮 **/
      dialog(id) {
        getEmployeefiles(id).then(response => {
          console.log(response)
          this.zzform = response.data;
        })
        this.dialogVisible = true;
      },

      /** 转正确定按钮 */
      zzSubmit() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.zzform.status = 4;
            updateEmployeefiles(this.zzform).then(response => {
              this.getList();

              this.dialogVisible = false;
              this.$modal.msgSuccess("操作成功");
            });
          }
        });

      },

      /** 搜索按钮操作 */
      handleQuery() {
        if (this.value2 != '' && this.value2 != null) {
          this.queryParams.beginTime = this.value2[0];
          this.queryParams.endTime = this.value2[1];
        }
        if (this.value2 == '' || this.value2 == null) {
          this.queryParams.beginTime = null;
          this.queryParams.endTime = null;
        }
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams = {
          pageNum: 1,
          pageSize: 10,
          name: null,
          gender: null,
          age: null,
          dateOfBirth: null,
          isMarriage: null,
          isBirth: null,
          ethnicGroup: null,
          politicalOutlook: null,
          documentType: null,
          identificationNumber: null,
          registeredResidence: null,
          phone: null,
          mailbox: null,
          currentAddress: null,
          emergencyContact: null,
          emergencyContactNumber: null,
          schoolName: null,
          education: null,
          major: null,
          bankCardNo: null,
          bankAddress: null,
          bankName: null,
          jobNo: null,
          deptName: null,
          title: null,
          workNature: null,
          employmentDate: null,
          probationPeriod: null,
          positionApplied: null,
          positionType: null,
          enterprise: null,
          status: null,
          enrollmentRegistration: null,
          contractSigning: null,
          socialSecuritySalary: null,
          isDelete: null,
          query: null,
          beginTime: null,
          endTime: null,
        }
        this.value2 = '';
        this.resetForm("queryForm");
        this.handleQuery();
      },

      parentIdChange(){
        this.$nextTick(()=>{
          this.$refs.form.validateField('deptName')
        })
      },
      /** 查询部门下拉树结构 */
      getDeptTree() {
        deptTreeSelect().then(response => {

          this.deptOptions = response.data;
        });
      },
    }
  };
</script>
